package tz.preprocessing;

import java.io.File;
import java.security.AccessControlContext;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeMap;

import tz.data.Article;
import tz.data.WekaAttribute;
import tz.data.WekaFile;
import tz.preprocessing.bagOfWords.BagOfWords;
import tz.util.TzHelper;

/**
 * 
 * @author dejvid
 *
 * Ustvarimo učno množico.
 * 
 */
public class Articles2WekaExport
{
	public static String wekaExportFile = "data/learninSet.arff";
	public static void main(String[] args) throws Exception
	{
		//1. Preberemo vse besede iz 
		Article2WordsCount.main(args); 
		WekaFile learningSet = new WekaFile();
		System.out.print("Processing list of attributes...");
		TzHelper.tic();
		List<String> lstWords = getListOfWords(Article2WordsCount.commonwords);
		
		learningSet.setRelation("BagOfWords");
		
		for(String s : lstWords)
		{
			WekaAttribute atr = new WekaAttribute(s,"real");
			learningSet.addAttribute(atr);
		}
		System.out.println(TzHelper.toc()+"ms");
		System.out.println("Num attributes: " + lstWords.size());
		
		System.out.print("Writing data to file...");
		TzHelper.tic();
		learningSet.write2wekaFileFormat(new File(wekaExportFile), Article2WordsCount.articleCountWords);
		System.out.println(TzHelper.toc() + "ms");
		System.out.println("DONE");
	}
	
	public static List<String> getListOfWords(TreeMap<String, Integer> tree)
	{
		ArrayList<String> al = new ArrayList<String>();
		for(String word : tree.keySet())
		{
			al.add(word);
		}
		return al;
	}
}

